package com.dyc.caradvertisting.ui.fmt.bind;


import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.dyc.caradvertisting.R;
import com.dyc.caradvertisting.bean.req.BindBean;
import com.dyc.caradvertisting.bean.req.SetBean;
import com.dyc.caradvertisting.comm.GsonUtils;
import com.dyc.caradvertisting.event.StartBrotherEvent;
import com.dyc.caradvertisting.ui.fmt.bind.bs.BindSetFmt;
import com.dyc.caradvertisting.ui.fmt.bind.vh.SetListVH;
import com.dyc.caradvertisting.widget.bindset.LoadingLayout;
import com.dyc.caradvertisting.widget.bindset.TBRecyclerView;
import com.dyc.caradvertisting.widget.trView.TRecyclerView;
import com.njh.tools.base.BaseFragment;
import com.njh.tools.common.userInfo.SPUserInfo;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 绑定设备列表
 */
public class BindSetListFmt extends BaseFragment<BindSetPresenter,BindSerModel> implements BindSerContract.View {

    @BindView(R.id.toolbar_title_tv)
    TextView toolbarTitleTv;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tr_set_list)
    TBRecyclerView trSetList;

    public BindSetListFmt() {
        // Required empty public constructor
    }

    public static BindSetListFmt newInstance() {
        BindSetListFmt fragment = new BindSetListFmt();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_bind_set_list;
    }

    @Override
    public void initView(View baseView) {
        ButterKnife.bind(this, baseView);
        initToolbarNav(R.string.title_my_car);
        trSetList.setView(SetListVH.class,mPresenter)
                .setParam("uid", GsonUtils.getmGson().toJson(new SetBean(SPUserInfo.getUid(this.getContext()))));
        trSetList.mloading_view.setOnloadingListener(new LoadingLayout.OnloadingListener() {
            @Override
            public void onEmpty(int id) {
                switch (id) {
                    case R.id.btn_bind_set:
                        // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                        EventBus.getDefault().post(new StartBrotherEvent(BindSetFmt.newInstance()));
                        break;
                    case R.id.btn_sp_sett:
                        Toast.makeText(BindSetListFmt.this._mActivity, "进入购买界面", Toast.LENGTH_SHORT).show();
                        break;
                }
            }

            @Override
            public void onError() {

            }
        });
        trSetList.fetch();
    }

    @Override
    public boolean isSwipeBack() {
        return true;
    }

    @Override
    public void initPresenter() {
     mPresenter.setVM(this,mModel,this._mActivity);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return getView(inflater, container);
    }

    @Override
    public void finish() {
        this.onBackPressedSupport();
    }
}
